const axios =require('axios');
const config=require("../config/config");
const getData = (resp) => resp.data;

//通过code获取access_token
async function get_access_token_by_code(code){
    const APPID=config.wechat_AppID;
    const SECRET=config.wechat_AppSecret;
    const CODE=code;
    const url=`https://api.weixin.qq.com/sns/oauth2/access_token?appid=${APPID}&secret=${SECRET}&code=${CODE}&grant_type=authorization_code`;
    const result=axios.get(url).then(getData);
    return result;
}
//通过code获取access_token
async function get_xcx_access_token_by_code(code){
    const APPID=config.xcx_AppID;
    const SECRET=config.xcx_AppSecret;
    const CODE=code;
    const url=`https://api.weixin.qq.com/sns/jscode2session?appid=${APPID}&secret=${SECRET}&js_code=${CODE}&grant_type=authorization_code`
    const result=axios.get(url).then(getData);
    return result;
}



module.exports={
    get_access_token_by_code,
    get_xcx_access_token_by_code,
};